package com.app.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ConsolePanel extends JPanel {
  private JTextArea textArea;
  private JTextField inputField;

  public ConsolePanel() {
    setLayout(new BorderLayout());

    textArea = new JTextArea();
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);
    add(scrollPane, BorderLayout.CENTER);

    inputField = new JTextField();
    inputField.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        String input = inputField.getText();
        textArea.append("> " + input + "\n");
        inputField.setText("");
        // Here you can add code to process the input command
      }
    });
    add(inputField, BorderLayout.SOUTH);
  }

  public void appendOutput(String output) {
    textArea.append(output + "\n");
  }
}